import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:graduation_project/cartoon_module/cartoon_list_three.dart';
import 'package:graduation_project/common/global.dart';

class bookrack_leader_list extends StatefulWidget {
  bookrack_leader_list(
      {Key key, this.cartoon_list1, this.allCounter, this.setstate})
      : super(key: key);
  bool setstate;
  List cartoon_list1 = [];
  ValueChanged<bool> allCounter;
  @override
  State<bookrack_leader_list> createState() => _bookrack_leader_listState();
}

class _bookrack_leader_listState extends State<bookrack_leader_list> {
  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: EdgeInsets.only(top: 50, bottom: 80),
      // padding: EdgeInsets.only(top: 10),
      // height: MediaQuery.of(context).size.height,
      // color: Colors.red,
      child: RefreshIndicator(
        onRefresh: () async {
          //模拟网络请求
          setState(() {
            // rank_num = 0;
          });
          print('上拉刷新');
          await Future.delayed(Duration(milliseconds: 2000));
          //结束刷新
          return Future.value(true);
        },
        child: ListView.builder(
            itemCount: 1,
            // controller: _scrollController,
            itemBuilder: (BuildContext context, int index) {
              return Container(
                alignment: Alignment.center,
                child: Wrap(
                  // spacing: 10,
                  children: widget.cartoon_list1
                      .asMap()
                      .keys
                      .map((e) => GestureDetector(
                            onTap: () {
                              // cartoon
                              setState(() {
                                widget.setstate
                                    // ignore: unnecessary_statements
                                    ? {
                                        widget.cartoon_list1[e]['setstate']
                                            ? widget.cartoon_list1[e]
                                                ['setstate'] = false
                                            : widget.cartoon_list1[e]
                                                ['setstate'] = true,
                                        widget.allCounter(true),
                                        for (var i = 0;
                                            i < widget.cartoon_list1.length;
                                            i++)
                                          {
                                            if (!widget.cartoon_list1[i]
                                                ['setstate'])
                                              {widget.allCounter(false)}
                                          }
                                      }
                                    : e == widget.cartoon_list1.length - 1
                                        ? setState(() => pageIndex = 1)
                                        :
                                        // ignore: unnecessary_statements
                                        {
                                            print(widget.cartoon_list1[e]
                                                ['cartoon_id']),
                                            setState(() {
                                              widget.cartoon_list1[e]
                                                  ['read_new'] = true;
                                              // print(cartoon_list1[e]);
                                            })
                                          };
                                // print(widget.)
                              });
                            },
                            child: Container(
                              margin: EdgeInsets.only(
                                  left: 4, right: 4, bottom: 4, top: 4),
                              width: 120,
                              height: 210,
                              child: OverflowBox(
                                child: Column(
                                  children: [
                                    Container(
                                      decoration: new BoxDecoration(
                                        color: Color.fromRGBO(255, 255, 255, 1),
                                        // 设置四周圆角，角度
                                        borderRadius: BorderRadius.all(
                                            Radius.circular(4.0)),
                                        border: new Border.all(
                                            color: Colors.black38, width: 0.5),
                                      ),
                                      child: Stack(children: [
                                        Image(
                                            height: 160,
                                            width: 120,
                                            fit: BoxFit.fill,
                                            image: NetworkImage(
                                                widget.cartoon_list1[e]
                                                    ['cartoon_leader_image'])),
                                        Transform.translate(
                                          offset: Offset(-2, -2),
                                          child: widget.cartoon_list1[e]['stae']
                                              // false
                                              ? Container(
                                                  width: 34,
                                                  height: 17,
                                                  color: Color.fromRGBO(
                                                      53, 142, 249, 1),
                                                  child: Container(
                                                    margin: EdgeInsets.only(
                                                        top: 2, left: 3),
                                                    child: Text(
                                                      'END',
                                                      style: TextStyle(
                                                          color: Colors.white,
                                                          fontSize: 12),
                                                    ),
                                                  ),
                                                )
                                              : (widget.cartoon_list1[e]
                                                      ['read_new']
                                                  // true
                                                  ? Container()
                                                  : Container(
                                                      width: 34,
                                                      height: 17,
                                                      color: Color.fromRGBO(
                                                          249, 86, 135, 1),
                                                      child: Container(
                                                        margin: EdgeInsets.only(
                                                            top: 2, left: 3),
                                                        child: Text(
                                                          'NEW',
                                                          style: TextStyle(
                                                              color:
                                                                  Colors.white,
                                                              fontSize: 12),
                                                        ),
                                                      ),
                                                    )),
                                        ),
                                        Container(
                                          height: 160,
                                          width: 120,
                                          color: widget.setstate
                                              ? Color.fromRGBO(30, 30, 30, 0.4)
                                              : null,
                                        ),
                                        Offstage(
                                          offstage: !widget.setstate,
                                          child: Checkbox(
                                              value: widget.cartoon_list1[e]
                                                  ['setstate'],
                                              onChanged: (value) {
                                                // value ?
                                              }),
                                        )
                                      ]),
                                    ),
                                    Row(children: [
                                      Container(
                                        margin:
                                            EdgeInsets.only(bottom: 4, top: 4),
                                        width: 104,
                                        child: Text(
                                          widget.cartoon_list1[e]
                                              ['cartoon_name'],
                                          // '123',
                                          style: TextStyle(fontSize: 12),
                                        ),
                                      ),
                                    ]),
                                    Row(
                                      children: [
                                        Container(
                                          margin: EdgeInsets.only(
                                            top: 2,
                                          ),
                                          child: Text(
                                            widget.cartoon_list1[e]
                                                    ['read_page'] +
                                                widget.cartoon_list1[e]
                                                    ['all_page'],
                                            // '123',
                                            style: TextStyle(
                                                fontSize: 10,
                                                color: Colors.black54),
                                          ),
                                        )
                                      ],
                                    )
                                  ],
                                ),
                              ),
                            ),
                          ))
                      .toList(),
                ),
              );
            }),
      ),
    );
  }
}
